Repository navigation
Widen loop counters flagged by CodeQL - #1
Merged
Merged
Conversation
CodeQL cpp/comparison-with-wider-type flagged ten loops whose counter is narrower than the expression it is compared against. If the bound ever exceeds the counter's range the counter wraps and the loop never ends. Most bounds here are small in practice, but sendPronto() is reachable with a sequence ending at 65535, where i += 2 wraps a uint16_t to 0. Each counter now has the bound's width, or the comparison is rewritten so both sides are the same type (i + 1 < length rather than i < length - 1, which keeps the zero-length case false). No behaviour change for valid input; host tests unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves the 10
cpp/comparison-with-wider-typealerts from code scanning (#10–#19).Each flagged loop compares a counter against a wider bound. If the bound exceeds the counter's range, the counter wraps and the loop never terminates.
IRutils.cppuint16_t i→int i(compared with adecode_type_t)ir_Daikin.cppuint8_t i→uint16_t iir_Kelvinator.cppuint16_t iandi + 1 < lengthinstead ofi < length - 1(zero length stays false)ir_Mitsubishi.cppuint8_t i→uint16_t iir_Panasonic.cppuint32_tblock counter against a precomputeduint32_ttotalir_Pronto.cppuint32_t iagainst a precomputed end. This one is a real bug: a sequence ending at 65535 madei += 2wrap auint16_tto 0.ir_Samsung.cpppos + kSamsungAcSectionLength <= nbits / 8instead of subtractingir_Samsung.cppuint8_t i→uint16_t iBehaviour for valid input is unchanged.
Not addressed here: #20 (
cpp/weak-cryptographic-algorithmonencodeRC5) is a false positive. RC5 is the Philips infrared protocol, not the RC5 cipher, and renaming the function would break the public API. It should be dismissed as a false positive in code scanning.Verified locally: 1669 host tests pass, cpplint is clean, and
ac_controlbuilds on IDF 5.5.5 with no warnings.